package role

import (
	"x-admin/backend/internal/middleware"

	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
)

// RegisterRoutes 注册角色管理路由
func RegisterRoutes(r *gin.RouterGroup, db *gorm.DB) {
	// 创建依赖
	repo := NewRepository(db)
	service := NewService(repo)
	handler := NewHandler(service)

	// 创建权限路由组
	roleGroup := middleware.NewPermissionGroup(r.Group("/roles"), db)
	{
		roleGroup.GET("", "role:list", handler.List)                                             // 获取角色列表
		roleGroup.GET("/all", "role:list", handler.GetAllRoles)                                  // 获取所有角色
		roleGroup.GET("/:id", "role:view", handler.GetByID)                                      // 获取角色详情
		roleGroup.POST("", "role:create", handler.Create)                                        // 创建角色
		roleGroup.PUT("/:id", "role:update", handler.Update)                                     // 更新角色
		roleGroup.DELETE("/:id", "role:delete", handler.Delete)                                  // 删除角色
		roleGroup.POST("/:id/permissions", "role:assign_permissions", handler.AssignPermissions) // 分配权限
	}
}
